﻿package com.wandian.util
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;

    public class CLZPanel extends Object
    {
        private var _mcPanel:Sprite;
        private var okFun:Function;
        private var closeFun:Function;

        public function CLZPanel(param1:Sprite, param2:Function = null, param3:Function = null) : void
        {
            if (this._mcPanel != null)
            {
                this.remove();
            }
            this.okFun = param2;
            this.closeFun = param3;
            this._mcPanel = param1;
            Texas.I._mcWindosView.addChildTo(this._mcPanel);
            Texas.I._mcWindosView.centerXY(this._mcPanel, 0, -30);
            if (this._mcPanel["cancel_btn"] != null)
            {
                this._mcPanel["cancel_btn"].addEventListener(MouseEvent.CLICK, this.onCloseHandler);
            }
            if (this._mcPanel["close_btn"] != null)
            {
                this._mcPanel["close_btn"].addEventListener(MouseEvent.CLICK, this.onCloseHandler);
            }
            if (this._mcPanel["ok_btn"] != null)
            {
                this._mcPanel["ok_btn"].addEventListener(MouseEvent.CLICK, this.onOKHandler);
            }
            return;
        }

        public function onCloseHandler(event:MouseEvent) : void
        {
            if (this.closeFun == null)
            {
                this.okFun();
            }
            else
            {
                this.closeFun();
            }
            return;
        }

        public function onOKHandler(event:MouseEvent) : void
        {
            this.okFun();
            return;
        }

        public function remove() : void
        {
            if (this._mcPanel != null)
            {
                if (this._mcPanel["cancel_btn"] != null)
                {
                    this._mcPanel["cancel_btn"].removeEventListener(MouseEvent.CLICK, this.onCloseHandler);
                }
                if (this._mcPanel["close_btn"] != null)
                {
                    this._mcPanel["close_btn"].removeEventListener(MouseEvent.CLICK, this.onCloseHandler);
                }
                if (this._mcPanel["ok_btn"] != null)
                {
                    this._mcPanel["ok_btn"].removeEventListener(MouseEvent.CLICK, this.onOKHandler);
                }
                Texas.I._mcWindosView.removeChildTo(this._mcPanel);
                this._mcPanel = null;
            }
            return;
        }

    }
}
